<?php

namespace app\yue\home;

// use GatewayClient\Gateway;

// use workerman timer to request index per 1 sec
class Timer extends Common
{
    public function index()
    {
        $round        = model('yue_round');
        $round_member = model('yue_round_member');
        $pay          = $this->getWechatPay();

        $rounds_to_refund = $round->where(['status' => 1, 'cash' => ['>', 0], 'create_time' => ['<', time() - 3600 * 12]])->select();
        foreach ($rounds_to_refund as $v) {
            $members = $round_member->where('rid', $v['id'])->select();
            foreach ($members as $val) {
                $result = $pay->refund($val['out_trade_no'], $val['transaction_id'], self::getBillno(), $v->cash * 100, $v->cash * 100);
            }
            $v->save(['status' => 3]);
        }

    }
}
